#!/bin/sh
# -*- sh -*-
# vim: ft=sh

: << =cut

=head1 NAME

bitcoind_blockchain_size - Plugin to monitor the size of the blockchain

=head1 CONFIGURATION

 [bitcoind*]
    user bitcoin
    env.data_dir /var/lib/bitcoin

=head1 AUTHOR

Cedric Felizard

=head1 LICENSE

AGPLv3+

=head1 MAGIC MARKERS

 #%# family=auto
 #%# capabilities=autoconf

=cut

DATA_DIR=${data_dir:-"/var/lib/bitcoin"}
BLOCK_DIR="${DATA_DIR}/blocks"
CONF_PATH=${conf_path:-"/etc/bitcoin.conf"}
if [ "$1" = "autoconf" ]; then
    autoconf="yes"

    [ -d $BLOCK_DIR ] || autoconf="no"

    echo $autoconf
    exit 0
fi

if [ "$1" = "config" ]; then
    echo 'graph_title Blockchain size'
    echo 'graph_vlabel size'
    echo 'graph_category bitcoind'
    echo 'graph_info This graph shows the size of the blockchain in bytes.'
    echo 'bitcoind_blockchain_size.label size'
    echo 'bitcoind_blockchain_size.info The size of the blockchain in bytes.'
    exit 0
fi

echo "bitcoind_blockchain_size.value $(du --block-size=1 -s $BLOCK_DIR | awk '{print $1}')"

